package com.woniuxy.hrms;

//完成HRMS后台操作

import com.woniuxy.hrms.dao.impl.IEmployeeDaolmplMen;
import com.woniuxy.hrms.entity.Employee;

import java.util.List;
import java.util.Scanner;

public class App {

    public static void main(String[] args) {
        System.out.println("welcome to woniu study!");
        Scanner scanner = new Scanner(System.in);//接受键盘输入信息
        String op = null;//接受用户选择的操作
        IEmployeeDaolmplMen employeeDao = new IEmployeeDaolmplMen();//创建员工操作对象
        while (true) {
            System.out.println("请选择操作菜单\n 1、查询所有员工；2、添加员工；3、修改员工；4、删除员工；5：id查询：9、退出系统");
            op = scanner.next();//得到输入的值
            if ("1".equals(op)) {//代表查询所有员工，比较字符串是否相等用equals当打，不能使用等于号
                List<Employee> employees = employeeDao.queryALL();
                for (Employee employee : employees) {
                    if (employee != null) {//不为0就输出员工
                        System.out.println(employee);
                    }
                }


            } else if ("2".equals(op)) {//代表添加员工
                System.out.println("请输入编号");
                int id = scanner.nextInt();
                System.out.println("请输入员工姓名");
                String name = scanner.next();
                System.out.println("请输入性别");
                String sex = scanner.next();
                System.out.println("请输入年龄");
                int age = scanner.nextInt();
                System.out.println("请输入薪水");
                double salary = scanner.nextDouble();
                Employee employee = new Employee(id, name, sex, age, salary);
                int add = employeeDao.add(employee);
                if (add > 0) {
                    System.out.println("添加成功");
                } else {
                    System.out.println("添加失败");
                }


            } else if ("3".equals(op)) {//代表修改
                System.out.println("请输入编号:");
                int id = scanner.nextInt();
                System.out.println("请输入员工姓名");
                String name = scanner.next();//接受输入的名称
                System.out.println("请输入性别");
                String sex = scanner.next();
                System.out.println("请输入年龄");
                int age = scanner.nextInt();
                System.out.println("请输入薪水");
                double salary = scanner.nextDouble();
                Employee employee = new Employee(id, name, sex, age, salary);
                int update = employeeDao.update(employee);
                if (update > 0) {
                    System.out.println("修改成功");
                } else {
                    System.out.println("修改失败");
                }


            } else if ("4".equals(op)) {//代表删除员工
                System.out.println("请输入要删除的员工的ID：");
                int id = scanner.nextInt();
                int delete = employeeDao.delete(id);
                if (delete > 0) {
                    System.out.println("删除成功");
                } else {
                    System.out.println("删除失败");
                }


            } else if ("5".equals(op)) {
                System.out.println("请输入要查的ID");
                int id = scanner.nextInt();
                Employee employee = employeeDao.queryByld(id);
                System.out.println(employee);

                
            } else if ("9".equals(op)) {//代表退出系统
                System.out.println("已退出");
                break;
            }
        }
        System.out.println("bye bye");
        scanner.close();
    }
}